#include "delay_us.h"
#include "tim.h"
#include "log.h"

void delay_us(uint32_t us)
{
	uint32_t lCur = htim5.Instance->CNT;
	uint32_t lTarget = lCur + us;


	if(lTarget > lCur)
	{
		while(lTarget > htim5.Instance->CNT)
		{
			;
		}
	}
	else
	{
		while(htim5.Instance->CNT > lTarget)
		{
			;
		}
		while(lTarget > htim5.Instance->CNT)
		{
			;
		}
	}
}

uint32_t getTick_us(void)
{
	return htim5.Instance->CNT;
}

int random_number(int min, int max)
{
	return htim5.Instance->CNT % (max - min + 1) + min;
}
